package cn.smile.config;

import cn.smile.commons.constant.NumberConstant;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MyBatis Plus 分页插件
 *
 * @author smile-jt
 */
@Slf4j
@Configuration
public class MyBatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        log.info("[MyBatisPlusConfig].[mybatisPlusInterceptor] ------> My Batis Plus 分页组件初始化 Start");
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 添加分页插件
        PaginationInnerInterceptor pageInterceptor = new PaginationInnerInterceptor();
        // 设置请求的页面大于最大页后操作，true调回到首页，false继续请求。默认false
        pageInterceptor.setOverflow(Boolean.FALSE);
        // 单页分页条数限制，默认无限制
        pageInterceptor.setMaxLimit(NumberConstant.MAX_LIMIT_VALUE);
        // 设置数据库类型
        pageInterceptor.setDbType(DbType.MYSQL);
        interceptor.addInnerInterceptor(pageInterceptor);
        log.info("[MyBatisPlusConfig].[mybatisPlusInterceptor] ------> My Batis Plus 分页组件初始化 End");
        return interceptor;
    }
}
